package org.gd136.ce.script.impl;

import java.util.ArrayList;

import org.gd136.ce.script.Script;
import org.gd136.ce.script.ScriptStage;

public class PartSignScript extends Script {

	String partName;

	@Override
	public Script readScript(String scriptLine) {
		PartSignScript ps = null;
		if (scriptLine.startsWith("@")) {
			ps = new PartSignScript();
			ps.partName = scriptLine.substring(1);
			if (ps.partName.charAt(0) == '@') {//ContinuePart
				if (SM.pool.containsKey(ps.partName)) {
					SM.currentPart = SM.pool.get(ps.partName);
				}
			} else {
				if (SM.pool.containsKey(ps.partName)) {
					throw new IllegalArgumentException(
							String.format("双重定义Part[%s]", ps.partName));
				}
				SM.currentPart = new ArrayList<>();
				SM.pool.put(ps.partName, SM.currentPart);
				ps.addToPool();
			}
		}
		return ps;
	}

	@Override
	public void execute(ScriptStage stage) {
		continueExecuteNext();
	}

}
